/**
  ******************************************************************************
  * @copyright 
  * @file      .c
  * @author    
  * @version   
  * @date      2022/7
  * @brief     
  ******************************************************************************
  * @attention     
    取模锟斤拷锟斤拷锟斤拷PCtoLCD2002
    锟斤拷锟斤拷 锟斤拷锟斤拷式 锟斤拷锟斤拷 C51锟斤拷式
  ******************************************************************************
  */
  
#include "task_web.h"


/*
 * 锟斤拷锟斤拷图片锟斤拷锟斤拷锟斤拷锟斤拷 img_add
 * 锟斤拷锟斤拷css js html锟斤拷锟斤拷锟斤拷锟斤拷 text_add
 * 锟斤拷锟斤拷锟斤拷锟捷诧拷锟斤拷锟斤拷锟斤拷 data_add
 *
 * 锟斤拷要锟斤拷锟斤拷component.mk锟叫碉拷锟斤拷锟斤拷,max_uri_handlers锟斤拷值锟斤拷锟斤拷锟斤拷锟阶�锟斤拷锟斤拷锟斤拷锟�
 */
uint32_t http_client_get_count = 0;
uint32_t sysRstCnt;
extern char *APP_VER;

/**********************************************************************锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷****WEB锟侥硷拷锟斤拷锟斤拷锟斤拷注锟斤拷 step2锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟介方式锟斤拷牛锟�******************************/
#if (0)
extern const uint8_t web_file_index_html_start[] asm("_binary_index_html_start");
extern const uint8_t web_file_index_html_end[] asm("_binary_index_html_end");
extern const uint8_t web_file_set_html_start[] asm("_binary_set_html_start");
extern const uint8_t web_file_set_html_end[] asm("_binary_set_html_end");
extern const uint8_t web_file_index_css_start[] asm("_binary_index_css_start");
extern const uint8_t web_file_index_css_end[] asm("_binary_index_css_end");
extern const uint8_t web_file_index_js_start[] asm("_binary_index_js_start");
extern const uint8_t web_file_index_js_end[] asm("_binary_index_js_end");
extern const uint8_t web_file_wifi_png_start[] asm("_binary_wifi_png_start");
extern const uint8_t web_file_wifi_png_end[] asm("_binary_wifi_png_end");
#else
#define ASM_START(name, format)					_binary_##name##_##format##_start
#define ASM_END(name, format)					_binary_##name##_##format##_end
#define toString(name)							#name
#define FILE_START(name, format, str)			extern const uint8_t web_file_##name##_##format##_start[] 	asm(toString(str))
#define FILE_END(name, format, str)				extern const uint8_t web_file_##name##_##format##_end[] 	asm(toString(str))
#define EXTERN_WEB_FILE(name, format)			FILE_START(name, format, ASM_START(name, format)); FILE_END(name, format, ASM_END(name, format))

#define WEB_FILE_ARRAY_START(name, format)		web_file_##name##_##format##_start
#define WEB_FILE_ARRAY_END(name, format)		web_file_##name##_##format##_end
#define WEB_FILE_ARRAY_SIZE(name, format)		(web_file_##name##_##format##_end - web_file_##name##_##format##_start)

//HTML
EXTERN_WEB_FILE(index, html);
EXTERN_WEB_FILE(set, html);
EXTERN_WEB_FILE(para, html);
EXTERN_WEB_FILE(button, html);	//text_add
EXTERN_WEB_FILE(adj, html);
EXTERN_WEB_FILE(others, html);
EXTERN_WEB_FILE(ntp, html);
EXTERN_WEB_FILE(weather, html);
#define PATH_index_html				"/"
#define PATH_set_html				"/html/set.html"
#define PATH_para_html				"/html/para.html"
#define PATH_button_html			"/html/button.html"	//text_add
#define PATH_adj_html				"/html/adj.html"
#define PATH_others_html			"/html/others.html"
#define PATH_ntp_html				"/html/ntp.html"
#define PATH_weather_html			"/html/weather.html"
//CSS
EXTERN_WEB_FILE(index, css);
#define PATH_index_css				"/css/index.css"
//JS
EXTERN_WEB_FILE(index, js);
EXTERN_WEB_FILE(jquery, js);
#define PATH_index_js				"/js/index.js"
#define PATH_jquery_js				"/js/jquery.js"
//image
EXTERN_WEB_FILE(set, png);
EXTERN_WEB_FILE(wifi, png);
EXTERN_WEB_FILE(dq, png);
EXTERN_WEB_FILE(gx, png);
EXTERN_WEB_FILE(rst, png);
EXTERN_WEB_FILE(info, png);
EXTERN_WEB_FILE(up, png);
EXTERN_WEB_FILE(down, png);
EXTERN_WEB_FILE(left, png);
EXTERN_WEB_FILE(right, png);
EXTERN_WEB_FILE(center, png);
EXTERN_WEB_FILE(adj, png);
EXTERN_WEB_FILE(button, png);
EXTERN_WEB_FILE(data, png);
EXTERN_WEB_FILE(dataName, png);
EXTERN_WEB_FILE(para, png);
EXTERN_WEB_FILE(ad, png);	//img_add
EXTERN_WEB_FILE(k, png);
EXTERN_WEB_FILE(on, png);
EXTERN_WEB_FILE(off, png);
EXTERN_WEB_FILE(ntp, png);
EXTERN_WEB_FILE(weather, png);
#define PATH_set_png				"/img/set.png"
#define PATH_wifi_png				"/img/wifi.png"
#define PATH_dq_png					"/img/dq.png"
#define PATH_gx_png					"/img/gx.png"
#define PATH_rst_png				"/img/rst.png"
#define PATH_info_png				"/img/info.png"
#define PATH_up_png					"/img/up.png"
#define PATH_down_png				"/img/down.png"
#define PATH_left_png				"/img/left.png"
#define PATH_right_png				"/img/right.png"
#define PATH_center_png				"/img/center.png"
#define PATH_adj_png				"/img/adj.png"
#define PATH_button_png				"/img/button.png"
#define PATH_data_png				"/img/data.png"
#define PATH_dataName_png			"/img/dataName.png"
#define PATH_para_png				"/img/para.png"
#define PATH_ad_png					"/img/ad.png"	//img_add
#define PATH_k_png					"/img/k.png"
#define PATH_on_png					"/img/on.png"
#define PATH_off_png				"/img/off.png"
#define PATH_ntp_png				"/img/ntp.png"
#define PATH_weather_png			"/img/weather.png"

//锟斤拷锟斤拷wifi锟斤拷锟斤拷位锟斤拷锟斤拷锟斤拷
#define NAME_hlwData				hlwData
#define NAME_rst					rst
#define NAME_wificfg				wificfg
#define NAME_hlwAC					hlwAC
#define NAME_btPara					btPara	//data_add
#define NAME_adjPara				adjPara
#define NAME_adjReq					adjReq
#define NAME_otaInfo				otaInfo
#define NAME_otherSet				otherSet
#define NAME_ntp					ntp

#define PATH_hlwData				"/hlwData"
#define PATH_rst					"/rst"
#define PATH_wificfg				"/wificfg"
#define PATH_hlwAC					"/hlwAC"
#define PATH_btPara					"/btPara"	//data_add
#define PATH_adjPara				"/adjPara"
#define PATH_adjReq					"/adjReq"
#define PATH_otaInfo				"/otaInfo"
#define PATH_otherSet				"/otherSet"
#define PATH_ntp					"/ntp"

#endif


/**********************************************************************锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷****WEB锟侥硷拷锟斤拷锟斤拷锟斤拷注锟斤拷 step3锟斤拷uri锟斤拷锟斤拷锟接︼拷拇锟斤拷锟斤拷锟绞斤拷锟斤拷募锟斤拷锟截碉拷锟斤拷锟斤拷锟斤拷******************************/
esp_err_t web_http_get_text_handler(httpd_req_t *req);
esp_err_t web_http_get_images_handler(httpd_req_t *req);
esp_err_t echo_post_handler(httpd_req_t *req);

#if (0)
httpd_uri_t html_index = {.uri = "/", .method = HTTP_GET, .handler = web_http_get_handler, .user_ctx = WEB_FILE_ARRAY_START(index, html) };
httpd_uri_t html_set = {.uri = "/html/set.html", .method = HTTP_GET, .handler = web_http_get_handler, .user_ctx = WEB_FILE_ARRAY_START(set, html) };
httpd_uri_t css_index = {.uri = "/css/index.css", .method = HTTP_GET, .handler = web_http_get_handler, .user_ctx = WEB_FILE_ARRAY_START(index, css) };
httpd_uri_t js_index = {.uri = "/js/index.js", .method = HTTP_GET, .handler = web_http_get_handler, .user_ctx = WEB_FILE_ARRAY_START(index, js) };
httpd_uri_t img_set = {.uri = "/img/set.png", .method = HTTP_GET, .handler = web_http_get_handler, .user_ctx = WEB_FILE_ARRAY_START(set, png) };
httpd_uri_t img_wifi = {.uri = "/img/wifi.png", .method = HTTP_GET, .handler = web_http_get_handler, .user_ctx = WEB_FILE_ARRAY_START(wifi, png) };
httpd_uri_t img_dq = {.uri = "/img/dq.png", .method = HTTP_GET, .handler = web_http_get_handler, .user_ctx = WEB_FILE_ARRAY_START(dq, png) };
#else
#define WEB_FILE_HTTPD_URI_REGISTER(dir, name, format, path, method_, handler_)	httpd_uri_t dir##_##name = \
																				{ \
																					.uri = path, \
																					.method = method_, \
																					.handler = handler_, \
																					.user_ctx = WEB_FILE_ARRAY_START(name, format) \
																				}
#define CMD_HTTPD_URI_REGISTER(name, path, method_, handler_)					httpd_uri_t name = \
																				{ \
																					.uri = path, \
																					.method = method_, \
																					.handler = handler_, \
																					.user_ctx = NULL \
																				}

WEB_FILE_HTTPD_URI_REGISTER(html, index, html, PATH_index_html, HTTP_GET, web_http_get_text_handler);
WEB_FILE_HTTPD_URI_REGISTER(html, set, html, PATH_set_html, HTTP_GET, web_http_get_text_handler);
WEB_FILE_HTTPD_URI_REGISTER(html, para, html, PATH_para_html, HTTP_GET, web_http_get_text_handler);
WEB_FILE_HTTPD_URI_REGISTER(html, button, html, PATH_button_html, HTTP_GET, web_http_get_text_handler);	//text_add
WEB_FILE_HTTPD_URI_REGISTER(html, adj, html, PATH_adj_html, HTTP_GET, web_http_get_text_handler);
WEB_FILE_HTTPD_URI_REGISTER(html, others, html, PATH_others_html, HTTP_GET, web_http_get_text_handler);
WEB_FILE_HTTPD_URI_REGISTER(css, index, css, PATH_index_css, HTTP_GET, web_http_get_text_handler);
WEB_FILE_HTTPD_URI_REGISTER(js, index, js, PATH_index_js, HTTP_GET, web_http_get_text_handler);
WEB_FILE_HTTPD_URI_REGISTER(js, jquery, js, PATH_jquery_js, HTTP_GET, web_http_get_text_handler);
WEB_FILE_HTTPD_URI_REGISTER(html, ntp, html, PATH_ntp_html, HTTP_GET, web_http_get_text_handler);
WEB_FILE_HTTPD_URI_REGISTER(html, weather, html, PATH_weather_html, HTTP_GET, web_http_get_text_handler);

WEB_FILE_HTTPD_URI_REGISTER(img, set, png, PATH_set_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, wifi, png, PATH_wifi_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, dq, png, PATH_dq_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, gx, png, PATH_gx_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, rst, png, PATH_rst_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, info, png, PATH_info_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, adj, png, PATH_adj_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, up, png, PATH_up_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, down, png, PATH_down_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, left, png, PATH_left_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, right, png, PATH_right_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, center, png, PATH_center_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, button, png, PATH_button_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, data, png, PATH_data_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, dataName, png, PATH_dataName_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, para, png, PATH_para_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, ad, png, PATH_ad_png, HTTP_GET, web_http_get_images_handler);	//img_add
WEB_FILE_HTTPD_URI_REGISTER(img, k, png, PATH_k_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, on, png, PATH_on_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, off, png, PATH_off_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, ntp, png, PATH_ntp_png, HTTP_GET, web_http_get_images_handler);
WEB_FILE_HTTPD_URI_REGISTER(img, weather, png, PATH_weather_png, HTTP_GET, web_http_get_images_handler);

CMD_HTTPD_URI_REGISTER(NAME_hlwData, PATH_hlwData, HTTP_GET, web_http_get_text_handler);
CMD_HTTPD_URI_REGISTER(NAME_rst, PATH_rst, HTTP_POST, echo_post_handler);
CMD_HTTPD_URI_REGISTER(NAME_wificfg, PATH_wificfg, HTTP_POST, echo_post_handler);
CMD_HTTPD_URI_REGISTER(NAME_hlwAC, PATH_hlwAC, HTTP_GET, web_http_get_text_handler);
CMD_HTTPD_URI_REGISTER(NAME_btPara, PATH_btPara, HTTP_GET, web_http_get_text_handler);	//data_add
CMD_HTTPD_URI_REGISTER(NAME_adjPara, PATH_adjPara, HTTP_GET, web_http_get_text_handler);
CMD_HTTPD_URI_REGISTER(NAME_adjReq, PATH_adjReq, HTTP_POST, echo_post_handler);
CMD_HTTPD_URI_REGISTER(NAME_otaInfo, PATH_otaInfo, HTTP_GET, web_http_get_text_handler);
CMD_HTTPD_URI_REGISTER(NAME_otherSet, PATH_otherSet, HTTP_GET, web_http_get_text_handler);
CMD_HTTPD_URI_REGISTER(NAME_ntp, PATH_ntp, HTTP_GET, web_http_get_text_handler);

#endif




#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif

#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT      BIT1

static const char *TAG = "HTTP SERVER";

extern uint32_t esp_get_time(void);

static bool logClear = false;


/* An HTTP GET handler */
esp_err_t web_http_get_text_handler(httpd_req_t *req)
{
    char*  buf;
    size_t buf_len;
    static uint8_t insertLog = 0;


    /* Get header value string length and allocate memory for length + 1,
     * extra byte for null termination */
    buf_len = httpd_req_get_hdr_value_len(req, "Host") + 1;
    if (buf_len > 1) {
        buf = malloc(buf_len);
        /* Copy null terminated value string into buffer */
        if (httpd_req_get_hdr_value_str(req, "Host", buf, buf_len) == ESP_OK) {
            ESP_LOGI(TAG, "Found header => Host: %s", buf);
        }
        free(buf);
    }

    /* Read URL query string length and allocate memory for length + 1,
     * extra byte for null termination */
    buf_len = httpd_req_get_url_query_len(req) + 1;
    if (buf_len > 1) {
        buf = malloc(buf_len);
        if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) {
            ESP_LOGI(TAG, "Found URL query => %s", buf);
            char param[32];
            /* Get value of expected key from query string */
            if (httpd_query_key_value(buf, "query1", param, sizeof(param)) == ESP_OK) {
                ESP_LOGI(TAG, "Found URL query parameter => query1=%s", param);
            }
            if (httpd_query_key_value(buf, "query3", param, sizeof(param)) == ESP_OK) {
                ESP_LOGI(TAG, "Found URL query parameter => query3=%s", param);
            }
            if (httpd_query_key_value(buf, "query2", param, sizeof(param)) == ESP_OK) {
                ESP_LOGI(TAG, "Found URL query parameter => query2=%s", param);
            }
        }
        free(buf);
    }

    /* Set some custom headers */
    httpd_resp_set_hdr(req, "Custom-Header-1", "Custom-Value-1");
    httpd_resp_set_hdr(req, "Custom-Header-2", "Custom-Value-2");

    /* Send response with custom headers and body set as the
     * string passed in user context*/

    //WEB锟侥硷拷锟斤拷锟斤拷锟斤拷注锟斤拷 step5 (GET锟斤拷锟斤拷锟斤拷锟絬ri锟斤拷注锟结，锟斤拷锟斤拷uri锟斤拷锟斤拷锟斤拷锟接︼拷锟斤拷募锟�)

    ESP_LOGI(TAG, req->uri);
    if (!strcmp(req->uri, PATH_index_css))	//css锟侥硷拷
    {
    	httpd_resp_set_type(req, "text/css");
    	const char* resp_str = (const char*) req->user_ctx;
    	httpd_resp_send(req, resp_str, strlen(resp_str));
    }
    else if (!strcmp(req->uri, PATH_hlwData))	//HLW8110 锟矫碉拷锟斤拷锟斤拷
	{
    	httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
    	char array[256];
    	memset(array, '\0', sizeof(array));
    	if ((logClear == true)	//锟斤拷锟揭筹拷锟斤拷锟街�/锟斤拷锟斤拷
    		|| ((warningLog.log.log_exist || warningLog.warning.warning_exist) && (++insertLog >= 5)))	//每10锟斤拷锟斤拷锟揭碉拷锟斤拷锟斤拷锟捷诧拷一锟斤拷锟斤拷志/锟斤拷锟斤拷(锟斤拷锟斤拷锟斤拷锟斤拷志/锟斤拷锟斤拷时)
		{
    		logClear = false;
			insertLog = 0;
			sprintf(array, "LOG,%u,%u", warningLog.log.log_exist, warningLog.warning.warning_exist);
		}
		else
		{
			sprintf(array, "%u,%u,%d,%u,%u,%d,%u,%u,%d,%s,%u,%u,%u,%u,%u,%u",
					HLW8110_.RmsU,
					HLW8110_.RmsIA,
					HLW8110_.PowerPA,
					HLW8110_.Energy_PA,
					HLW8110_.Ufreq,
					HLW8110_.PowerFactor,
					HLW8110_.Energy_PA_Zeroable,
					relay_get(),
					HLW8110_.PowerS,
					local_host_name,
					relayTask_t_.countDownEnable, relayTask_t_.countDownSeconds,
					relayTask_t_.powerDownEnable, relayTask_t_.powerDownCriticalVal, relayTask_t_.powerDownSeconds,
					HLW8110_.PriceZeroable);
		}
    	int cnt = 0;
    	for (; cnt < sizeof(array); cnt++)
    	{
    		if (array[cnt] == '\0')
    			break;
    	}
    	const char* resp_str = (const char*) array;
		httpd_resp_send(req, resp_str, cnt);
	}
    else if (!strcmp(req->uri, PATH_hlwAC))	//HLW8110 锟斤拷锟斤拷
	{
		httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
		char array[256];
		memset(array, '\0', sizeof(array));

		sprintf(array, "%u,%u,%u,%u,%u,%u,%u,%u,%u,%uh%um%us,%u,%s,%u,%d.%dW",
						HLW8110_.RmsUC,
						HLW8110_.RmsIAC,
						HLW8110_.PowerPAC,
						HLW8110_.PowerSC,
						HLW8110_.EnergyAC,
						HLW8110_.HFconst,
						HLW8110_.PFCntPA,
						HLW8110_.Energy_PA_Cnt,
						HLW8110_.Energy_PA_CntZeroable,
						timestamp_s_get() / 3600, timestamp_s_get() / 60 % 60, timestamp_s_get() % 60,
						sysRstCnt,
						APP_VER,
						HLW8110_.Energy_PA_CntMoney,
						HLW8110_.PowerPA_Average / 1000, HLW8110_.PowerPA_Average % 1000);
		int cnt = 0;
		for (; cnt < sizeof(array); cnt++)
		{
			if (array[cnt] == '\0')
				break;
		}
		const char* resp_str = (const char*) array;
		httpd_resp_send(req, resp_str, cnt);
	}
    else if (!strcmp(req->uri, PATH_btPara))	//锟斤拷锟斤拷锟斤拷锟斤拷 data_add
	{
		httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
		char array[256];
		buttonVal_t	buttonVal_;
		buttonVal_ = button_ad_get();
		memset(array, '\0', sizeof(array));
		sprintf(array, "%u,%u,%u,%u,%u,%u",
						buttonVal_.BUTTON_UP,
						buttonVal_.BUTTON_DOWN,
						buttonVal_.BUTTON_LEFT,
						buttonVal_.BUTTON_RIGHT,
						buttonVal_.BUTTON_CENTER,
						buttonVal_.BUTTON_VAL_NOW);
		int cnt = 0;
		for (; cnt < sizeof(array); cnt++)
		{
			if (array[cnt] == '\0')
				break;
		}
		const char* resp_str = (const char*) array;
		httpd_resp_send(req, resp_str, cnt);
	}
    else if (!strcmp(req->uri, PATH_adjPara))	//锟斤拷锟斤拷锟斤拷校准
	{
		httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
		char array[256];
		memset(array, '\0', sizeof(array));
		sprintf(array, "%u,%u",
				HLW8110_K_Get(HLW_KU),
				HLW8110_K_Get(HLW_KI));
		int cnt = 0;
		for (; cnt < sizeof(array); cnt++)
		{
			if (array[cnt] == '\0')
				break;
		}
		const char* resp_str = (const char*) array;
		httpd_resp_send(req, resp_str, cnt);
	}
    else if (!strcmp(req->uri, PATH_otaInfo))	//ota锟斤拷息
	{
		httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
		char array[256];
		uint32_t ota_size, ota_rec;
		get_fota_data(&ota_size, &ota_rec);
		memset(array, '\0', sizeof(array));
		sprintf(array, "%u,%u",
				ota_rec,
				ota_size);
		int cnt = 0;
		for (; cnt < sizeof(array); cnt++)
		{
			if (array[cnt] == '\0')
				break;
		}
		const char* resp_str = (const char*) array;
		httpd_resp_send(req, resp_str, cnt);
	}
    else if (!strcmp(req->uri, PATH_otherSet))	//锟斤拷锟斤拷锟斤拷锟斤拷
	{
		httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
		char array[256]; memset(array, '\0', sizeof(array));
		int len;
		memset(local_host_name, '\0', sizeof(local_host_name)); task_nvs_read_str(NVS_KEY_STR_LOCAL_NAME, local_host_name, &len);
		memset(FOTA_SEVER_IP, '\0', sizeof(FOTA_SEVER_IP)); task_nvs_read_str(NVS_KEY_STR_SERVER_IP, FOTA_SEVER_IP, &len);
		memset(FOTA_SEVER_PORT, '\0', sizeof(FOTA_SEVER_PORT)); task_nvs_read_str(NVS_KEY_STR_SERVER_PORT, FOTA_SEVER_PORT, &len);
		sprintf(array, "%u,%u,%s,%s,%s,%u %u %u,%uW %us,%u",
				FRAM_SAVE_DATA_NAME____DIDO_t_.BITS.Relay_ShouldRecover,
				FRAM_SAVE_DATA_NAME____DIDO_t_.BITS.Relay_Def,
				local_host_name,
				FOTA_SEVER_IP,
				FOTA_SEVER_PORT,
				oled_Set.oled_bl, oled_Set.oled_mode, oled_Set.oled_off,
				relayTask_t_.overloadCriticalVal, relayTask_t_.overloadSeconds,
				HLW8110_.PricePerkWh);
		int cnt = 0;
		for (; cnt < sizeof(array); cnt++)
		{
			if (array[cnt] == '\0')
				break;
		}
		const char* resp_str = (const char*) array;
		httpd_resp_send(req, resp_str, cnt);
	}
	else if (!strcmp(req->uri, PATH_ntp))	//NTP服务器
	{
		httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
		char array[256]; memset(array, '\0', sizeof(array));
		sprintf(array, "%s,%u",
				UserSetNTPServer, UserSetNTPInterval);
		int cnt = 0;
		for (; cnt < sizeof(array); cnt++)
		{
			if (array[cnt] == '\0')
				break;
		}
		const char* resp_str = (const char*) array;
		httpd_resp_send(req, resp_str, cnt);
	}
    else	//html锟斤拷js
    {
    	httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
    	ESP_LOGI(TAG, "text.html");
    	const char* resp_str = (const char*) req->user_ctx;
    	httpd_resp_send(req, resp_str, strlen(resp_str));
    }
    http_client_get_count++;


    /* After sending the HTTP response the old HTTP request
     * headers are lost. Check if HTTP request headers can be read now. */
    if (httpd_req_get_hdr_value_len(req, "Host") == 0) {
        ESP_LOGI(TAG, "Request headers lost");
    }
    return ESP_OK;
}

/* An HTTP GET handler */
esp_err_t web_http_get_images_handler(httpd_req_t *req)
{
    char*  buf;
    size_t buf_len;

    /* Get header value string length and allocate memory for length + 1,
     * extra byte for null termination */
    buf_len = httpd_req_get_hdr_value_len(req, "Host") + 1;
    if (buf_len > 1) {
        buf = malloc(buf_len);
        /* Copy null terminated value string into buffer */
        if (httpd_req_get_hdr_value_str(req, "Host", buf, buf_len) == ESP_OK) {
            ESP_LOGI(TAG, "Found header => Host: %s", buf);
        }
        free(buf);
    }

    /* Read URL query string length and allocate memory for length + 1,
     * extra byte for null termination */
    buf_len = httpd_req_get_url_query_len(req) + 1;
    if (buf_len > 1) {
        buf = malloc(buf_len);
        if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) {
            ESP_LOGI(TAG, "Found URL query => %s", buf);
            char param[32];
            /* Get value of expected key from query string */
            if (httpd_query_key_value(buf, "query1", param, sizeof(param)) == ESP_OK) {
                ESP_LOGI(TAG, "Found URL query parameter => query1=%s", param);
            }
            if (httpd_query_key_value(buf, "query3", param, sizeof(param)) == ESP_OK) {
                ESP_LOGI(TAG, "Found URL query parameter => query3=%s", param);
            }
            if (httpd_query_key_value(buf, "query2", param, sizeof(param)) == ESP_OK) {
                ESP_LOGI(TAG, "Found URL query parameter => query2=%s", param);
            }
        }
        free(buf);
    }

    /* Set some custom headers */
    httpd_resp_set_hdr(req, "Custom-Header-1", "Custom-Value-1");
    httpd_resp_set_hdr(req, "Custom-Header-2", "Custom-Value-2");

    /* Send response with custom headers and body set as the
     * string passed in user context*/

    //WEB锟侥硷拷锟斤拷锟斤拷锟斤拷注锟斤拷 step5 (GET锟斤拷锟斤拷锟斤拷锟絬ri锟斤拷注锟结，锟斤拷锟斤拷uri锟斤拷锟斤拷锟斤拷锟接︼拷锟斤拷募锟�)

    ESP_LOGI(TAG, req->uri);

	httpd_resp_set_type(req, "image/png");
	ESP_LOGI(TAG, "image.png");

	http_client_get_count++;

#define IMAGES_MATCH(name, format)		do { \
											if (!strcmp(req->uri, PATH_##name##_##format)) \
												httpd_resp_send(req, \
														(const char *)WEB_FILE_ARRAY_START(name, format), \
														WEB_FILE_ARRAY_SIZE(name, format)); \
											} while(0)
	//图片
	IMAGES_MATCH(wifi, png);
	IMAGES_MATCH(dq, png);
	IMAGES_MATCH(set, png);
	IMAGES_MATCH(gx, png);
	IMAGES_MATCH(rst, png);
	IMAGES_MATCH(info, png);
	IMAGES_MATCH(adj, png);
	IMAGES_MATCH(button, png);
	IMAGES_MATCH(up, png);
	IMAGES_MATCH(down, png);
	IMAGES_MATCH(left, png);
	IMAGES_MATCH(right, png);
	IMAGES_MATCH(center, png);
	IMAGES_MATCH(data, png);
	IMAGES_MATCH(dataName, png);
	IMAGES_MATCH(para, png);
	IMAGES_MATCH(ad, png);	//img_add
	IMAGES_MATCH(k, png);
	IMAGES_MATCH(on, png);
	IMAGES_MATCH(off, png);
	IMAGES_MATCH(ntp, png);
	IMAGES_MATCH(weather, png);

    /* After sending the HTTP response the old HTTP request
     * headers are lost. Check if HTTP request headers can be read now. */
    if (httpd_req_get_hdr_value_len(req, "Host") == 0) {
        ESP_LOGI(TAG, "Request headers lost");
    }
    return ESP_OK;
}




//WEB锟侥硷拷锟斤拷锟斤拷锟斤拷注锟斤拷 step6 锟斤拷POST锟斤拷锟斤拷锟秸达拷锟斤拷锟斤拷锟斤拷锟斤拷锟捷ｏ拷
/* An HTTP POST handler */
esp_err_t echo_post_handler(httpd_req_t *req)
{
    char buf[100];
    int ret, remaining = req->content_len;
    static uint32_t relayDelay = 0;


    while (remaining > 0) {
        /* Read the data for the request */
        if ((ret = httpd_req_recv(req, buf,
                        MIN(remaining, sizeof(buf)))) <= 0) {
            if (ret == HTTPD_SOCK_ERR_TIMEOUT) {
                /* Retry receiving if timeout occurred */
                continue;
            }
            return ESP_FAIL;
        }

        /* Send back the same data */
        httpd_resp_send_chunk(req, buf, ret);
        remaining -= ret;

        ESP_LOGI(TAG, req->uri);
        /* Log data received */
        ESP_LOGI(TAG, "=========== RECEIVED DATA ==========");
        ESP_LOGI(TAG, "%.*s", ret, buf);
        ESP_LOGI(TAG, "====================================");

        if (!strcmp(req->uri, PATH_rst))	//锟斤拷位
		{
        	if (!strncmp("sysRst", buf, 6)) {	//系统锟斤拷位
        		sys_restart();	//直锟接碉拷锟斤拷esp_restart();锟斤拷锟斤拷位锟斤拷锟斤拷俅谓锟斤拷盏锟斤拷锟轿恢革拷锟�
        	}
        	else if (!strncmp("ota", buf, 3)) {
        		xTaskCreate(&fota_task, "ota_task", 8192, NULL, 5, NULL);	//!!注锟斤拷锟斤拷锟斤拷锟絤enuconfig锟斤拷锟斤拷ota锟斤拷锟斤拷
        	}
        	else if (!strncmp("relayon", buf, 7)) {	//锟斤拷锟截继碉拷锟斤拷
        		if (relayDelay <= (timestamp_s_get() - 2))	//锟斤拷锟狡匡拷锟斤拷频锟斤拷
        		{
        			relayDelay = timestamp_s_get();
					uint8_t w;
					if (relay_get() == RELAY_ON) {
						relay_active(RELAY_OFF);
						w = 0;
					}
					else {
						relay_active(RELAY_ON);
						w = 1;
					}
					FRAM_HandleBits(FRAM_WRITE, DIDO__RELAY_ONOFF, &w);
        		}
			}
        	else if (!strncmp("relayLast", buf, 9)) {	//锟较碉拷时锟教碉拷锟斤拷锟街革拷之前锟斤拷状态
        		uint8_t w;
        		if (FRAM_SAVE_DATA_NAME____DIDO_t_.BITS.Relay_ShouldRecover == 0)
        			w = 1;
        		else
        			w = 0;
        		FRAM_HandleBits(FRAM_WRITE, DIDO__RELAY_SHOULD_RECOVER, &w);
			}
        	else if (!strncmp("relayDef", buf, 8)) {	//锟较碉拷时锟教碉拷锟斤拷锟街革拷之前锟斤拷状态 锟斤拷锟斤拷效时锟斤拷 执锟斤拷默锟较匡拷 / 锟斤拷
        		uint8_t w;
        		if (FRAM_SAVE_DATA_NAME____DIDO_t_.BITS.Relay_Def == 0)
					w = 1;
				else
					w = 0;
				FRAM_HandleBits(FRAM_WRITE, DIDO__RELAY_DEFAULT, &w);
				FRAM_HandleBits(FRAM_WRITE, DIDO__RELAY_ONOFF, &w);
        	}
        	else if (!strncmp("zeroable", buf, 8)) {	//锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
        		HLW8110_.Energy_PA_CntZeroable = HLW8110_.Energy_PA_Zeroable = 0;
        		FRAM_HandleWord(FRAM_WRITE, FRAM_SAVE_DATA_NAME____ENERGY_PA_CNT_ZEROABLE, &HLW8110_.Energy_PA_CntZeroable);
#if (0)	//锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷艿锟斤拷锟�
        		HLW8110_.Energy_PA_Cnt = HLW8110_.Energy_PA = 0;
        		FRAM_HandleWord(FRAM_WRITE, FRAM_SAVE_DATA_NAME____ENERGY_PA_CNT, &HLW8110_.Energy_PA_Cnt);
#endif
        	}
        	else if (!strncmp("priceZeroable", buf, 13)) {	//锟斤拷锟斤拷锟斤拷锟�
        		HLW8110_.PriceZeroable = HLW8110_.Energy_PA_CntMoney = HLW8110_.Energy_PA_Money = 0;
				FRAM_HandleWord(FRAM_WRITE, FRAM_SAVE_DATA_NAME____ENERGY_PA_CNT_MONEY, &HLW8110_.Energy_PA_CntMoney);
			}
        	else if (!strncmp("localName", buf, 9)) {	//锟斤拷路锟斤拷锟斤拷锟斤拷锟斤拷示锟斤拷锟斤拷锟斤拷
        		char name[32];
        		memset(name, '\0', sizeof(name));
        		uint8_t i;
				for (i = 0; i < sizeof(name); i++)
				{
					if (buf[i + 10] == ',')
						break;
					name[i] = buf[i + 10];
				}
				task_nvs_write_str(NVS_KEY_STR_LOCAL_NAME, name);
        	}
        	else if (!strncmp("serverIP", buf, 8)) {	//锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷IP
        		char name[32];
				memset(name, '\0', sizeof(name));
				uint8_t i;
				for (i = 0; i < sizeof(name); i++)
				{
					if (buf[i + 9] == ',')
						break;
					name[i] = buf[i + 9];
				}
				task_nvs_write_str(NVS_KEY_STR_SERVER_IP, name);
			}
        	else if (!strncmp("serverPORT", buf, 10)) {	//锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟剿匡拷
        		char name[32];
				memset(name, '\0', sizeof(name));
				uint8_t i;
				for (i = 0; i < sizeof(name); i++)
				{
					if (buf[i + 11] == ',')
						break;
					name[i] = buf[i + 11];
				}
				task_nvs_write_str(NVS_KEY_STR_SERVER_PORT, name);
			}
        	else if (!strncmp("oledSet", buf, 7)) {	//oled锟斤拷锟斤拷
				uint8_t val = 0;
				uint8_t i;
				for (i = 0; i < 8; i++)
				{
					if (buf[i + 8] == ',')
						break;
					val *= 10;
					val += buf[i + 8] - '0';
				}
				oled_Set.oled_bl = val;
				task_nvs_write_var(NVS_KEY_U8_OLED_BL, NVS_TYPE_U8, &val);
				i++;
				val = 0;
				for (; i < 16; i++)
				{
					if (buf[i + 8] == ',')
						break;
					val *= 10;
					val += buf[i + 8] - '0';
				}
				oled_Set.oled_mode = val;
				task_nvs_write_var(NVS_KEY_U8_OLED_MODE, NVS_TYPE_U8, &val);
				i++;
				val = 0;
				for (; i < 24; i++)
				{
					if (buf[i + 8] == ',')
						break;
					val *= 10;
					val += buf[i + 8] - '0';
				}
				oled_Set.oled_off = val;
				task_nvs_write_var(NVS_KEY_U8_OLED_OFF, NVS_TYPE_U8, &val);
			}
        	else if (!strncmp("cdCfg", buf, 5)) {	//锟斤拷锟斤拷时
				relayTask_t_.countDownSeconds = 0;
				uint8_t i;
				for (i = 0; i < 10; i++)
				{
					if (buf[i + 6] == ',')
						break;
					relayTask_t_.countDownSeconds *= 10;
					relayTask_t_.countDownSeconds += buf[i + 6] - '0';
				}
				if (relayTask_t_.countDownSeconds)
				{
					relayTask_t_.countDownEnable = true;
				}
				else
				{
					relayTask_t_.countDownEnable = false;
				}
			}
        	else if (!strncmp("pdCfg", buf, 5)) {	//锟斤拷锟斤拷小锟斤拷
				relayTask_t_.powerDownCriticalVal = relayTask_t_.powerDownSeconds = 0;
				uint8_t i;
				for (i = 0; i < 10; i++)
				{
					if (buf[i + 6] == ',')
						break;
					relayTask_t_.powerDownCriticalVal *= 10;
					relayTask_t_.powerDownCriticalVal += buf[i + 6] - '0';
				}
				i++;
				for (; i < 21; i++)
				{
					if (buf[i + 6] == ',')
						break;
					relayTask_t_.powerDownSeconds *= 10;
					relayTask_t_.powerDownSeconds += buf[i + 6] - '0';
				}
				relayTask_t_.powerDownSecondsRecord = relayTask_t_.powerDownSeconds;
				if (relayTask_t_.powerDownCriticalVal)
				{
					relayTask_t_.powerDownEnable = true;
				}
				else
				{
					relayTask_t_.powerDownEnable = false;
				}
			}
        	else if (!strncmp("overload", buf, 8)) {	//锟斤拷锟斤拷
				relayTask_t_.overloadCriticalVal = relayTask_t_.overloadSeconds = 0;
				uint8_t i;
				for (i = 0; i < 10; i++)
				{
					if (buf[i + 9] == ',')
						break;
					relayTask_t_.overloadCriticalVal *= 10;
					relayTask_t_.overloadCriticalVal += buf[i + 9] - '0';
				}
				i++;
				for (; i < 21; i++)
				{
					if (buf[i + 9] == ',')
						break;
					relayTask_t_.overloadSeconds *= 10;
					relayTask_t_.overloadSeconds += buf[i + 9] - '0';
				}
				relayTask_t_.overloadSecondsRecord = relayTask_t_.overloadSeconds;
				FRAM_HandleWord(FRAM_WRITE, FRAM_SAVE_DATA_NAME____OVERLOAD_CRITICAL, &relayTask_t_.overloadCriticalVal);
				FRAM_HandleWord(FRAM_WRITE, FRAM_SAVE_DATA_NAME____OVERLOAD_SECONDS, &relayTask_t_.overloadSeconds);
			}
        	else if (!strncmp("clearLog", buf, 8)) {	//锟斤拷锟斤拷锟街�/锟斤拷锟斤拷
        		warningLog.log.log_exist = 0;
        		warningLog.warning.warning_exist = 0;
        		logClear = true;
			}
		}
        else if (!strcmp(req->uri, PATH_wificfg))	//锟斤拷锟斤拷wifi
		{
        	if (!strncmp("ssid", buf, 4)) {
        		char wifissid[128];
        		char *wifissid_p = wifissid;
        		uint8_t i;
        		memset(wifissid, '\0', sizeof(wifissid));
        		for (i = 0; i < sizeof(wifissid); i++)
        		{
        			if (':' == buf[i]) {
        				i++;
        				break;
        			}
        		}
        		for (; i < sizeof(wifissid); i++)
				{
					if (';' == buf[i])
						break;
					*wifissid_p++ = buf[i];
				}
        		//ESP_LOGI(TAG, "ssid is %s", wifissid);
        		task_nvs_write_str(NVS_KEY_STR_WIFI_SSID, wifissid);
        		for (; i < sizeof(wifissid); i++)
				{
					if (':' == buf[i]) {
						i++;
						break;
					}
				}
        		wifissid_p = wifissid;
        		memset(wifissid, '\0', sizeof(wifissid));
        		for (; i < sizeof(wifissid); i++)
				{
					if (';' == buf[i])
						break;
					*wifissid_p++ = buf[i];
				}
				//ESP_LOGI(TAG, "pwd is %s", wifissid);
				task_nvs_write_str(NVS_KEY_STR_WIFI_PWD, wifissid);
        	}
		}
        else if (!strcmp(req->uri, PATH_adjReq))	//校准
		{
        	buttonVal_t	buttonVal_;
			buttonVal_ = button_ad_get();
        	if (!strncmp("BU", buf, 2)) {
        		task_nvs_write_var(NVS_KEY_U16_BUTTON_UP, NVS_TYPE_U16, &buttonVal_.BUTTON_VAL_NOW);
			}
        	else if (!strncmp("BD", buf, 2)) {
        		task_nvs_write_var(NVS_KEY_U16_BUTTON_DOWN, NVS_TYPE_U16, &buttonVal_.BUTTON_VAL_NOW);
			}
        	else if (!strncmp("BL", buf, 2)) {
        		task_nvs_write_var(NVS_KEY_U16_BUTTON_LEFT, NVS_TYPE_U16, &buttonVal_.BUTTON_VAL_NOW);
			}
        	else if (!strncmp("BR", buf, 2)) {
        		task_nvs_write_var(NVS_KEY_U16_BUTTON_RIGHT, NVS_TYPE_U16, &buttonVal_.BUTTON_VAL_NOW);
			}
        	else if (!strncmp("BC", buf, 2)) {
        		task_nvs_write_var(NVS_KEY_U16_BUTTON_CENTER, NVS_TYPE_U16, &buttonVal_.BUTTON_VAL_NOW);
			}
        	else if (!strncmp("KU", buf, 2)) {
        		uint32_t val = 0;
        		for (uint8_t i = 2; i < 8; i++)
        		{
        			if (buf[i] == ',')
        				break;
        			val *= 10;
        			val += (buf[i] - '0');
        		}
        		val = (uint32_t)((double)HLW8110_.RmsU_noAdj * 1000000 / val);
        		if (val >= KU_MIN && val <= KU_MAX)	//K值锟斤拷围(1.0-0.1, 1.0+0.1)
        		{
        			FRAM_HandleWord(FRAM_WRITE, FRAM_SAVE_DATA_NAME____KU, &val);
        		}
        	}
        	else if (!strncmp("KI", buf, 2)) {
        		uint32_t val = 0;
				for (uint8_t i = 2; i < 8; i++)
				{
					if (buf[i] == ',')
						break;
					val *= 10;
					val += (buf[i] - '0');
				}
				val = (uint32_t)((double)HLW8110_.RmsIA_noAdj * 1000000 / val);
				if (val >= KI_MIN && val <= KI_MAX)	//K值锟斤拷围(1.0-0.1, 1.0+0.1)
				{
					FRAM_HandleWord(FRAM_WRITE, FRAM_SAVE_DATA_NAME____KI, &val);
				}
			}
        	else if (!strncmp("PricePer", buf, 8)) {
				uint32_t val = 0;
				for (uint8_t i = 8; i < 16; i++)
				{
					if (buf[i] == ',')
						break;
					val *= 10;
					val += (buf[i] - '0');
				}
				HLW8110_.PricePerkWh = val;
				FRAM_HandleWord(FRAM_WRITE, FRAM_SAVE_DATA_NAME____PRICE_PER_KWH, &val);
			}
        	task_button_init();
        	HLW8110_K_Init();
		}
		else if (!strcmp(req->uri, PATH_ntp))	//NTP
		{
        	if (!strncmp("ntpService", buf, 10)) {	//NTP服务器
        		char name[32];
				memset(name, '\0', sizeof(name));
				uint8_t i;
				for (i = 0; i < sizeof(name); i++)
				{
					if (buf[i + 11] == ',')
						break;
					name[i] = buf[i + 11];
				}
				task_nvs_write_str(NVS_KEY_STR_NTP_SERVER, name);
			}
        	else if (!strncmp("getTimexHour", buf, 12)) {	//NTP校对间隔
        		uint32_t val = 0;
				uint8_t i;
				for (i = 13; i < 21; i++)
				{
					if (buf[i] == ',')
						break;
					val *= 10;
					val += buf[i] - '0';
				}
				UserSetNTPInterval = val;
				task_nvs_write_var(NVS_KEY_U16_NTP_MINUTE, NVS_TYPE_U16, &val);
			}
		}
    }

    // End response
    httpd_resp_send_chunk(req, NULL, 0);
    return ESP_OK;
}

httpd_uri_t echo = {
    .uri       = "/echo",
    .method    = HTTP_POST,
    .handler   = echo_post_handler,
    .user_ctx  = NULL
};






/* An HTTP PUT handler. This demonstrates realtime
 * registration and deregistration of URI handlers
 */
esp_err_t ctrl_put_handler(httpd_req_t *req)
{
    char buf;
    int ret;

    if ((ret = httpd_req_recv(req, &buf, 1)) <= 0) {
        if (ret == HTTPD_SOCK_ERR_TIMEOUT) {
            httpd_resp_send_408(req);
        }
        return ESP_FAIL;
    }

    if (buf == '0') {
        /* Handler can be unregistered using the uri string */
        ESP_LOGI(TAG, "Unregistering /hello and /echo URIs");
        httpd_unregister_uri(req->handle, "/hello");
        httpd_unregister_uri(req->handle, "/echo");
    }
    else {
        ESP_LOGI(TAG, "Registering /hello and /echo URIs");
        httpd_register_uri_handler(req->handle, &html_index);
        httpd_register_uri_handler(req->handle, &echo);
    }

    /* Respond with empty body */
    httpd_resp_send(req, NULL, 0);
    return ESP_OK;
}

httpd_uri_t ctrl = {
    .uri       = "/ctrl",
    .method    = HTTP_PUT,
    .handler   = ctrl_put_handler,
    .user_ctx  = NULL
};

httpd_handle_t start_webserver(void)
{
    httpd_handle_t server = NULL;
#if 0
    httpd_config_t config = HTTPD_DEFAULT_CONFIG();
    config.max_uri_handlers = 40;	//锟斤拷值锟斤拷锟斤拷锟阶�锟斤拷锟斤拷锟斤拷锟�
#else
    httpd_config_t config = {
    	.task_priority      = tskIDLE_PRIORITY+5,
		.stack_size         = 4096,
		.server_port        = 80,
		.ctrl_port          = 32768,
		.max_open_sockets   = 12,	//锟斤拷锟襟，筹拷锟皆斤拷锟� httpd_accept_conn: error in accept(23)锟斤拷锟竭碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟街伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟街伙拷锟斤拷锟诫开一锟斤拷锟劫伙拷锟斤拷锟斤拷锟斤拷wifi却锟斤拷锟襟不碉拷页锟斤拷锟斤拷锟斤拷锟�
		.max_uri_handlers   = 45,	//锟斤拷值锟斤拷锟斤拷锟阶�锟斤拷锟斤拷锟斤拷锟�
		.max_resp_headers   = 8,
		.backlog_conn       = 5,
		.lru_purge_enable   = true,	//锟斤拷为true锟斤拷锟斤拷锟斤拷锟截憋拷锟斤拷锟斤拷锟阶斤拷锟街ｏ拷锟斤拷锟皆斤拷锟� httpd_accept_conn: error in accept(23)锟斤拷锟竭碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟街伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟街伙拷锟斤拷锟诫开一锟斤拷锟劫伙拷锟斤拷锟斤拷锟斤拷wifi却锟斤拷锟襟不碉拷页锟斤拷锟斤拷锟斤拷锟�
		.recv_wait_timeout  = 5,
		.send_wait_timeout  = 5,
		.global_user_ctx = NULL,
		.global_user_ctx_free_fn = NULL,
		.global_transport_ctx = NULL,
		.global_transport_ctx_free_fn = NULL,
		.open_fn = NULL,
		.close_fn = NULL,
    };
#endif
    // Start the httpd server
    ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
    if (httpd_start(&server, &config) == ESP_OK) {
        // Set URI handlers
        ESP_LOGI(TAG, "Registering URI handlers");
        //WEB锟侥硷拷锟斤拷锟斤拷锟斤拷注锟斤拷 step4锟斤拷注锟斤拷氐锟斤拷锟絊DK锟斤拷锟秸碉拷uri锟斤拷锟斤拷扫锟斤拷锟斤拷锟铰碉拷uri锟斤拷锟斤拷匹锟戒）
        httpd_register_uri_handler(server, &echo);
        httpd_register_uri_handler(server, &ctrl);
        																//锟斤拷锟斤拷目锟斤拷锟矫筹拷锟斤拷max_uri_handlers
        httpd_register_uri_handler(server, &html_index);
        httpd_register_uri_handler(server, &html_set);
        httpd_register_uri_handler(server, &html_para);
        httpd_register_uri_handler(server, &html_button);	//text_add
        httpd_register_uri_handler(server, &html_adj);
        httpd_register_uri_handler(server, &html_others);
        httpd_register_uri_handler(server, &css_index);
        httpd_register_uri_handler(server, &js_index);
        httpd_register_uri_handler(server, &js_jquery);
		httpd_register_uri_handler(server, &html_ntp);
        httpd_register_uri_handler(server, &html_weather);
																		//锟斤拷锟斤拷目锟斤拷锟矫筹拷锟斤拷max_uri_handlers
        httpd_register_uri_handler(server, &img_dq);
        httpd_register_uri_handler(server, &img_set);
        httpd_register_uri_handler(server, &img_wifi);
        httpd_register_uri_handler(server, &img_gx);
        httpd_register_uri_handler(server, &img_rst);
        httpd_register_uri_handler(server, &img_info);
        httpd_register_uri_handler(server, &img_button);
        httpd_register_uri_handler(server, &img_adj);
        httpd_register_uri_handler(server, &img_up);
        httpd_register_uri_handler(server, &img_down);
        httpd_register_uri_handler(server, &img_left);
        httpd_register_uri_handler(server, &img_right);
        httpd_register_uri_handler(server, &img_center);
        httpd_register_uri_handler(server, &img_data);
        httpd_register_uri_handler(server, &img_dataName);
        httpd_register_uri_handler(server, &img_para);
        httpd_register_uri_handler(server, &img_ad);	//img_add
        httpd_register_uri_handler(server, &img_k);
        httpd_register_uri_handler(server, &img_on);
        httpd_register_uri_handler(server, &img_off);
		httpd_register_uri_handler(server, &img_ntp);
		httpd_register_uri_handler(server, &img_weather);
																		//锟斤拷锟斤拷目锟斤拷锟矫筹拷锟斤拷max_uri_handlers
        httpd_register_uri_handler(server, &NAME_hlwData);
        httpd_register_uri_handler(server, &NAME_rst);
        httpd_register_uri_handler(server, &NAME_wificfg);
        httpd_register_uri_handler(server, &NAME_hlwAC);
        httpd_register_uri_handler(server, &NAME_btPara);	//data_add
        httpd_register_uri_handler(server, &NAME_adjPara);
        httpd_register_uri_handler(server, &NAME_adjReq);
        httpd_register_uri_handler(server, &NAME_otaInfo);
        httpd_register_uri_handler(server, &NAME_otherSet);
		httpd_register_uri_handler(server, &NAME_ntp);
        return server;
    }

    ESP_LOGI(TAG, "Error starting server!");
    return NULL;
}




static httpd_handle_t server = NULL;



void Start_WebServer(void)
{
	server = start_webserver();
}









